import { InvokeArgs, invoke } from "@tauri-apps/api/tauri";
import * as event from "@tauri-apps/api/event";
export const handleIsTauri = () => {
  return Boolean(
    typeof window !== "undefined" &&
      window !== undefined &&
      window.__TAURI_IPC__ !== undefined,
  );
};
export const appInvoke = async <T>(
  cmd: string,
  args?: InvokeArgs,
): Promise<T> => {
  if (!handleIsTauri()) return Promise.resolve(() => {}) as T;
  return invoke(cmd, args);
};
export const appEvent = <T>(
  name: event.EventName,
  handler: event.EventCallback<T>,
): Promise<() => void> => {
  if (!handleIsTauri()) return Promise.resolve(() => {});
  return event.listen(name, handler);
};
